﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace CoderJoe.WoW.GearManager
{
	public abstract class Model
		: INotifyPropertyChanged, INotifyPropertyChanging
	{

		private PropertyStore Store { get; set; }
		private PropertyChangedEventHandler m_propertyChangedHandler;
		private PropertyChangingEventHandler m_propertyChangingHandler;

		public Model()
		{
			Store = new PropertyStore(OnPropertyChanged, OnPropertyChanging);
		}

		public void SetInvokeOwner(ISynchronizeInvoke invoker)
		{
			Store.SetInvokeOwner(invoker);
		}

		protected void ClearStore()
		{
			Store.Clear();
		}

		protected TResult GetValue<TResult>(string propertyName, TResult defaultValue)
		{
			return Store.GetValue<TResult>(propertyName, defaultValue);
		}

		protected void SetValue<TResult>(string propertyName, TResult value)
		{
			Store.SetValue<TResult>(propertyName, value);
		}

		protected void OnPropertyChanged(PropertyChangedEventArgs args)
		{
			if (m_propertyChangedHandler != null)
				m_propertyChangedHandler(this, args);
		}

		protected void OnPropertyChanging(PropertyChangingEventArgs args)
		{
			if (m_propertyChangingHandler != null)
				m_propertyChangingHandler(this, args);
		}

		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged
		{
			add { m_propertyChangedHandler += value; }
			remove { m_propertyChangedHandler -= value; }
		}

		#endregion

		#region INotifyPropertyChanging Members

		public event PropertyChangingEventHandler PropertyChanging
		{
			add { m_propertyChangingHandler += value; }
			remove { m_propertyChangingHandler -= value; }
		}

		#endregion
	}



}
